//
//  FilterMethod.swift
//  ECApp
//
//  Created by 程平 on 2017/10/22.
//

import Foundation
import PerfectHTTP
import PerfectLogger

class FilterMethod:HTTPRequestFilter {
  
   
    
 
    
     func filter(request: HTTPRequest, response: HTTPResponse, callback: (HTTPRequestFilterResult) -> ()) {
         LogFile.debug("方法过滤")
        if request.method == .get && forbiddenGetMethodOfPaths.contains(request.path) {
            let result = ResponseData.jsonData(resultCode: ResultCode.methodUnavailable, data: nil) 
            try! response.setBody(json: result)
            response.setHeader(.contentLength, value: "\(response.bodyBytes.count)")
            response.setHeader(.contentType, value: ResponseData.contentType)//访问地址有误
            response.status = HTTPResponseStatus.ok
            print("禁止执行了")
            callback(.halt(request, response))
        }else{
             callback(.continue(request, response))
        }
       
    }
    
    
}
